package com.suncaper.tddmall.service;

import com.suncaper.tddmall.common.model.Category;
import com.suncaper.tddmall.common.model.CategoryExample;
import com.suncaper.tddmall.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    CategoryMapper categoryMapper;

    //通过关键字查询
    @Override
    public List<Category> searchByKeywords(String keywords) {
        CategoryExample categoryExample = new CategoryExample();
        categoryExample.createCriteria().andKeywordsLike("%" + keywords + "%");
        List<Category> categoryList = categoryMapper.selectByExample(categoryExample);

        return categoryList;
    }

    @Override
    public List<Map> searchByPrice(Integer maxPrice, Integer minPrice) {
        List<Map> listMap = categoryMapper.searchByPrice(maxPrice, minPrice);
        for (Map map :
                listMap) {
            for (Object key :
                    map.keySet()) {
                System.out.println("key=" + key + "///" + "value=" + map.get(key));
            }
        }

        return listMap;
    }
}